package springtest.nettySocketio.service;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;

import springtest.nettySocketio.User;

/**
 * @author chenzhiqiang
 * @date 2018-07-04 13:56:41
 */
@Service
public class SendDataService {
    @Autowired
    private SocketIOServer server;

    public void sendData() {
        Collection<SocketIOClient> clients = server.getAllClients();
        for (SocketIOClient client : clients) {
            // 此处发送时间的名字，需要与前端接受事件的名字一样
            User user = new User();
            user.setId("123");
            user.setName("test");
            client.sendEvent("hello", user);
        }
    }
}
